﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace FGUFW.Play.StackedTower
{
    public class Cube : MonoBehaviour
    {
        public AnimationCurve AnimCurve;
        public int Level=1;
        public float MoveSpace=20;
        float _startTime;

        // Start is called before the first frame update
        void Start()
        {
            _startTime = Time.time;
            GetComponent<MeshRenderer>().material.color = new Color32((byte)Random.Range(0,256),(byte)Random.Range(0,256),(byte)Random.Range(0,256),255);
        }

        // Update is called once per frame
        void Update()
        {
            float time = Time.time-_startTime;
            float space = AnimCurve.Evaluate(time)*MoveSpace/2;
            if(Level%2==0)
            {
                transform.localPosition = new Vector3(0,Level+0.5f,space);
            }
            else
            {
                transform.localPosition = new Vector3(space,Level+0.5f,0);
            }
        }

        void OnDestroy()
        {

        }
    }
}
